/**
 * Copyright (C), 2015-2018，XXX人名
 * FileName: TestService
 * Author:   Administrator
 * Date:     2018/4/3 14:19
 * Description: 业务层测试类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.desheng.Service;


import com.desheng.bean.User;
import com.desheng.bean.UserExample;
import com.desheng.dao.UserMapper;
import com.desheng.util.MybatisUtil;
import com.easyFramework.annotation.Service;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈业务层测试类〉
 *
 * @author Administrator
 * @create 2018/4/3
 * @since 1.0.0
 */
@Service
public class TestService {

    public User find(Long userId, String password) {
        //获取SqlSession
        SqlSession session = MybatisUtil.openSession();
        //获取UserMapper
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user= new User();
        user.setUserid(userId);
        user.setPassword(password);
        //执行Mapper中的find方法
        UserExample ue =new UserExample();
        UserExample.Criteria uec =ue.createCriteria();
        uec.andUseridEqualTo(userId);
        uec.andPasswordEqualTo(password);
        List<User> userList= userMapper.selectByExample(ue);
        if(userList.size()>0){
            //关闭SqlSession
            session.close();
            return userList.get(0);
        }
        return null;
    }

//    public boolean add(User user){
//        //获取SqlSession
//        SqlSession session = MybatisUtil.openSession();
//        //获取UserMapper
//        UserMapper userMapper = session.getMapper(UserMapper.class);
//        System.out.println("service"+user.getUsername()+":"+user.getPassword());
//        UserExample ue =new UserExample();
//        UserExample.Criteria uec =ue.createCriteria();
//        userMapper.insert(user);
//        session.commit();
//        session.close();
//
//    }

}
